/*
 =============================================================================
 FILE...............: Airport.java
 COMMENTS...........: Model of an airport.
 =============================================================================
 AUTHOR(S)..........: Everton Ranielly de Sousa Cavalcante
 					  Department of Informatics and Applied Mathematics
 					  Federal University of Rio Grande do Norte
 LAST MODIFICATION..: September 18th, 2012
 ============================================================================= 					  
*/


/* ========================================================================= */
/* PACKAGES			                                                         */
/* ------------------------------------------------------------------------- */
package model;

import javax.xml.bind.annotation.XmlRootElement;


/* ========================================================================= */
/* CLASS Airport	                                                         */
/* ------------------------------------------------------------------------- */
/**
 * Model of an airport
 * @author Everton Cavalcante
 */
@XmlRootElement
public class Airport 
{
	private String airportIATACode;			// IATA 3-letter code
	private String airportICAOCode;			// ICAO 4-letter code
	private String airportName;				// Airport name
	private String airportLocation;			// Airport location
	
	
	/** Default constructor */
	public Airport()
	{ /* Empty */ }
	
	
	/** Constructor */
	public Airport(String airportIATACode, String airportICAOCode, String airportName, String airportLocation)
	{
		if ((airportIATACode.length() == 0 && airportICAOCode.length() != 4) ||
			(airportIATACode.length() != 3 && airportICAOCode.length() == 0))
		{
			System.out.println("Invalid airport code");
			return;
		}
		else
		{
			this.setAirportIATACode(airportIATACode);
			this.setAirportICAOCode(airportICAOCode);
			this.setAirportName(airportName);
			this.setAirportLocation(airportLocation);
		}
	}
	
	
	/**
	 * Returns the airport IATA 3-letter code
	 * @return airportCode Airport IATA code
	 */
	public String getAirportIATACode() 
	{ return new String(airportIATACode); }
	
	
	/**
	 * Modifies the airport IATA 3-letter code
	 * @param airportCode Airport IATA code to set
	 */
	public void setAirportIATACode(String airportCode) 
	{
		if (airportCode.length() != 0 && airportCode.length() != 3)
		{
			System.out.println("Invalid airport code");
			return;
		}
		else 
			this.airportIATACode = airportCode; 
	}
	
	
	/**
	 * Returns the airport ICAO 4-letter code
	 * @return airportCode Airport ICAO code
	 */
	public String getAirportICAOCode() 
	{ return new String(airportICAOCode); }
	
	
	/**
	 * Modifies the airport ICAO 4-letter code
	 * @param airportCode Airport ICAO code to set
	 */
	public void setAirportICAOCode(String airportCode) 
	{
		if (airportCode.length() != 0 && airportCode.length() != 4)
		{
			System.out.println("Invalid airport code");
			return;
		}
		else 
			this.airportICAOCode = airportCode; 
	}
	
	
	/**
	 * Returns the airport name
	 * @return airportName Airport name
	 */
	public String getAirportName() 
	{ return airportName; }
	
	
	/**
	 * Modifies the airport name
	 * @param airportName Airport name to set
	 */
	public void setAirportName(String airportName) 
	{ this.airportName = airportName; }
	
	
	/**
	 * Returns the airport location
	 * @return airportLocation Airport location
	 */
	public String getAirportLocation() 
	{ return airportLocation; }
	
	
	/**
	 * Modifies the airport location
	 * @param airportLocation Airport location to set
	 */
	public void setAirportLocation(String airportLocation) 
	{ this.airportLocation = airportLocation; }
	
	
	@Override
	public String toString()
	{
		String code = (this.getAirportIATACode().equals("")) ? this.getAirportICAOCode() : this.getAirportIATACode();
		String airport = code + " - " + this.getAirportName() + " (" + this.getAirportLocation() + ")";
		return airport;
	}
}
